package org.dromara.business.api;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject;
import jakarta.annotation.security.PermitAll;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.business.domain.StakingProduct;
import org.dromara.business.domain.bo.UserStakingBo;
import org.dromara.business.domain.vo.UserStakingVo;
import org.dromara.business.request.StakingRequest;
import org.dromara.business.service.IStakingProductService;
import org.dromara.business.service.IUserStakingService;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.domain.model.AppLoginUser;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/product")
public class ProductApi {

    private final IStakingProductService stakingProductService;
    private final IUserStakingService userStakingService;

    @GetMapping("/list")
    @PermitAll
    public R<List<StakingProduct>> getList() {
        List<StakingProduct> products = stakingProductService.getList();
        return R.ok(products);
    }

    /**
     * 质押
     * @param request
     * @return
     */
    @PostMapping("/stake")
    public R<Void> createStaking(@Valid @RequestBody StakingRequest request) {
        userStakingService.createStaking(request);
        return R.ok();
    }

    @GetMapping("/listUserStaking")
    public R<TableDataInfo<UserStakingVo>> listUserStaking(UserStakingBo bo, PageQuery pageQuery) {
        AppLoginUser loginUser = LoginHelper.getAppLoginUser();
        bo.setUserId(loginUser.getUserId());
        return R.ok(userStakingService.queryPageList(bo, pageQuery));
    }
}
